﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using OntoWPFSilverlight.Xml;

namespace OntoWPFSilverlight
{
    public class Node
    {
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Name { get; set; }
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Type { get ; set; }
        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public int Weight { get; set; }

        public List<Node> Childs {get; set;}
        private Node father = null;

        [XmlNodeTypeAttribute(System.Xml.XmlNodeType.Attribute)]
        public String Alias { get; set; }
        
        public Node()
        {
            Childs = new List<Node>();
            Name = "";
            Type = "";
            Alias = "";
            Weight = 0;
        }

        public override string ToString()
        {
            String sReturn = "Name: " + this.Name + " sono di tipo " + Type + " e ho: " + this.Childs.Count + " figli/o";
            //sReturn += "Father: " + this.father == null ? "nessuno" : this.father.ToString();
            foreach (Node node in this.Childs)
            {
                sReturn += "\n\tFigli " + node.Name;
            }

            foreach (Node node in this.Childs)
            {
                sReturn += "\n\t\tFigli " + node.ToString();
            }

            sReturn += "\n";

            return sReturn;
        }

        public Node Father
        {
            get { return father; }
            set { father = value; }
        }

       
        public static int CompareNodeByWeight(int x, int y)
        {
            return x.CompareTo(y);
        }

        public static int CompareNodeByWeight(Node x, Node y)
        {
            return x.Weight.CompareTo(y.Weight);
        }

        public int CompareNodeByWeight(Node _node) {
            return this.Weight.CompareTo(_node.Weight);
        }
    }
}
